package boot.util;

import boot.common.CommonResult;
import boot.service.cache.RedisCache;
import com.alibaba.fastjson.JSON;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cb
 * @create 2022-09-08-14:45
 */
@Component
public class parseTokenUtil {

    public String parseToken(Map map) throws Exception {
        String tokenObject = map.get("authorization").toString();
        String token = JSON.parseObject(tokenObject, HashMap.class).get("token").toString();
        String username;
        Claims claims = JwtUtil.parseJWT(token);
        username = claims.getSubject();
        return username;

    }
    public String getToken(Map map) throws Exception {
        String tokenObject = map.get("authorization").toString();
        String username;
        Claims claims = JwtUtil.parseJWT(tokenObject);
        username = claims.getSubject();
        return username;

    }
}
